﻿using System.Linq;
using System.Web.Mvc;
using TrainingManagerSystem.WebUI.Models;
namespace TrainingManagerSystem.WebUI.Controllers
{
    public class AccountCourseController : Controller
    {
        /// <summary>
        /// GET:view account course default
        /// </summary>
        /// <returns></returns>
        public ActionResult AccountCourseIndex()
        {
            var host = ManagerClientService.Client();

            var accoutCourse = host.GetAccountCourseByPaging(20, 1, null, null, 0, null, null, null, null, 0, 0, 0, null, null, 0, 0, 0);

            ViewBag.Data = AcountCourse.GetDataForTreeView(host.ListAllDepartment(0).ToList());
            ViewBag.DataCategory = CourseExtensionHelper.GetDataForTreeView(host.CourseCategoryFetchAllName().ToList());
            return View(accoutCourse);
        }

        [HttpPost]
        public JsonResult GetLocation()
        {
            var host = ManagerClientService.Client();
            return Json(host.FetchAllLocation().ToList());
        }
        /// <summary>
        /// POST: give result when paging
        /// </summary>
        /// <param name="pageSize"></param>
        /// <param name="pageNumber"></param>
        /// <param name="filters"> </param>
        /// <returns></returns>
        [HttpPost]
        public JsonResult AccountCoursePaging(int pageSize, int pageNumber, string filters)
        {
            var arr = filters.Split(',');
            var host = ManagerClientService.Client();
            for (var i = 0; i < arr.Length; i++)
            {
                if (arr[i] == "") arr[i] = null;
            }
            var list = host.GetAccountCourseByPaging(pageSize, pageNumber, arr[0], arr[1], 0, arr[3], arr[4], arr[5], arr[6], int.Parse(arr[7]), 0, 0, null, arr[10], 0, 0, int.Parse(arr[13]));
            return Json(list);
        }
    }
}
